﻿Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Xml.Linq
Imports GenDotNet.TemplateSupport
Imports GenDotNet.TemplateSupport.VB
Imports GenDotNet.Task.Common
Imports GenDotNet.ObjectModel
Imports GenDotNet.TemplateSupport.Strings
Imports <xmlns:orm="http://kadgen.com/KADORM.xsd">
Imports <xmlns="http://kadgen.com/tempCode.xsd">

Public MustInherit Class DotNetBase
   Inherits DotNetLanguageBase

   Protected Sub New()
   End Sub

   Protected Function GetChildTypeName(ByVal child As IChildData) As String
      If Not child.IsHierarchy Then
         Return child.Name & "Collection"
      End If
      Return child.Name
   End Function

   Protected Function GetChildNewMethodName(ByVal child As IChildData) As String
      If child.IsHierarchy Then
         Return "NewHierarchy"
      End If
      Return "NewCollection"
   End Function

   Friend Shared Function MemberPropertyInfo( _
            ByVal prop As IPropertyData, _
            ByVal currentTypeInfo As TypeInfo) _
            As PropertyInfo
      Dim propInfo = New PropertyInfo(prop.Name, currentTypeInfo, _
                     Scope.Public, prop.NetType, _
                     prop.IsReadOnly, _
                     Function() MemberPropertyAccessGet(prop), _
                     Function() MemberPropertyAccessSet(prop))
      propInfo.GetAttributes.AddNoInlining()
      propInfo.SetAttributes.AddNoInlining()
      Return propInfo
   End Function

   Private Shared Function MemberPropertyAccessGet(ByVal propertyData As IPropertyData) As String
      Return _
<Code>
      CanReadProperty("<%= propertyData.Name %>", True)
         Return m<%= propertyData.Name %>
</Code>.Value
   End Function

   Private Shared Function MemberPropertyAccessSet(ByVal propertyData As IPropertyData) As String
      Return _
<code>
         CanWriteProperty("<%= propertyData.Name %>", true)
         If m<%= propertyData.Name %> &lt;> value Then
            m<%= propertyData.Name %> = value
            PropertyHasChanged("<%= propertyData.Name %>")
         End If
</code>.Value
   End Function
End Class
